# -*- coding: utf8 -*-
import threading
import xmpp
from PyQt4 import QtCore

class Jabber(QtCore.QThread):
	def registerHandler(self,tipo,handler):
		self.jabber.RegisterHandler(tipo,handler)
	def xmppConnect(self,host='localhost',usuario='admin',password='admin',puerto='5222'):
		self.jabber = xmpp.Client(host,debug=[])
		if self.jabber.connect(server=(host,int(puerto))) == '':
			return False
		if self.jabber.auth(usuario,password,'Home') == None:
			return False
		else:
			self.jabber.sendPresence(typ='available')
	def sendMessage(self,usuario,mensaje):
		self.jabber.send(xmpp.Message(usuario,mensaje))	
	def StepOn(self):
		try:
			self.jabber.Process(1)
		except KeyboardInterrupt:
			return 0
		return 1
	def run(self):
		while self.StepOn():
			pass
